//
//  ScrollView.m
//  UI_09homework
//
//  Created by dllo on 16/6/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ScrollView.h"

@implementation ScrollView


-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.picsArray = [NSArray array];
        [self setPropertys];
//        [self addpics:_picsArray];
    }
    
    return  self;
}


-(void)setPropertys{
    
    self.showsHorizontalScrollIndicator = NO;
    self.showsVerticalScrollIndicator = NO;
    
    self.pagingEnabled = YES;
    
}

-(void)addpics:(NSArray<UIImage *> *)imagesArray{
    
    self.contentSize = CGSizeMake(self.frame.size.width * imagesArray.count, CGRectGetHeight(self.bounds)) ;
    
    for (int i = 0; i < imagesArray.count; i++) {
        UIImageView *imageView = [[UIImageView alloc]initWithImage:imagesArray[i]];
        imageView.frame = CGRectMake(i * CGRectGetWidth(self.bounds), 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds));
        
        [self addSubview:imageView];
        [imageView release];
        
    }
    
}





-(void)setPicsArray:(NSArray *)picsArray{
    if (_picsArray != picsArray) {
        [_picsArray release];
       _picsArray =  [picsArray retain];
    }
    
    [self addpics:_picsArray];
    
    
}








@end
